<template>
  <virtual-table-layout :form-title="`推进信息表(${queryParams.pageNo})`">
    <virtual-table
      :handler-get-list="getDetail"
      v-model:page-no="queryParams.pageNo"
      v-model:page-data="pageData"
      :total="queryParams.total"
      :page-size="queryParams.pageSize"
    >
      <view v-for="(page, key) in pageData" :key="page.pageNo">
        <view class="pm-pt-item mb10" v-for="(item, key) in page.list" :key="'pm-pt-item_' + key">
          <d-card>
            <d-forms disabled label-width="200rpx">
              <d-forms-item label="主题描述" :input="item.subjectDescription"></d-forms-item>
              <d-forms-item label="推进时间" :type="DFormInputType.DATE" :input="item.propelTime"></d-forms-item>
              <d-forms-item label="客户参与人员" :input="item.customerParticipants"></d-forms-item>
              <d-forms-item label="我司参与人员">
                <pm-user-select disabled :user-id="item.ourParticipantIds"></pm-user-select>
              </d-forms-item>
              <d-forms-item label="推进情况" :input="item.advanceSituation"></d-forms-item>
              <d-forms-item label="问题描述" :input="item.problemsEncountered"></d-forms-item>
              <d-forms-item label="解决情况" :input="item.solveSituation"></d-forms-item>
              <view>
                <view class="form-title-1">文件上传</view>
                <pm-file-upload v-if="item.fileUrl" readonly :files="item.fileUrl"></pm-file-upload>
                <view v-else>暂无</view>
              </view>
            </d-forms>
          </d-card>
        </view>
      </view>
    </virtual-table>
  </virtual-table-layout>
</template>

<script setup lang="ts">
import {usePmPromotionInfoApi} from "@/api/pm/project/promotionInfo";
import VirtualTableLayout from "@/components/VirtualTableLayout/index.vue";
import {DFormInputType} from "@/utils/enum";

const triggered = ref<boolean>(false);
const pageData = ref<VirtualTableData<PmPromotionForm>[]>([]);

function getDetail() {
  return new Promise((resolve, reject) => {
    if (projectNumber.value) {
      usePmPromotionInfoApi().getPromotionPage({
        projectNumber: projectNumber.value,
        ...queryParams
      }).then(res => {
        if (res.code === 0 && res.data) {
          queryParams.total = res.data.total;
          resolve(res.data.list);
        } else {
          reject(res.data)
        }
      }).catch((err) => {
        reject(err);
      })
    } else {
      resolve([])
    }
  })
}

const queryParams = reactive<{
  pageSize: number,
  pageNo: number,
  total: number,
}>({
  pageSize: 5,
  pageNo: 1,
  total: 0,
})

const projectNumber = ref<string>();
onLoad((query) => {
  projectNumber.value = query['project_number'];
  getDetail()
})
</script>

<style scoped lang="scss">

</style>
